<template>
  <div>
    <h3>展示发布的评论</h3>
    {{fabu}}
    <table style="width:800px; margin:0 auto">
        <tr>
            <td>编号</td>
            <td>用户名</td>
            <td>文章名</td>
            <td>作者</td>
            <td>文章内容</td>
            <td>操作</td>
        </tr>
        <tr v-for="(item,i) in fabu" :key="i">
            <td>{{item.id}}</td>
            <td>{{item.user_name}}</td>
            <td>{{item.art_name}}</td>
            <td>{{item.art_author}}</td>
            <td>{{item.art_content}}</td>
            <td>
                <button @click="delOne(item.id)">删除</button>
            </td>
        </tr>
    </table>
    <div>
        <input type="text" v-model="name">  <button @click="searchOne">搜索作者名</button>
        {{searchlist}}
    </div>

  </div>
</template>

<script>
import axios from 'axios'
export default {
    data(){
        return{
            fabu:[],
            name:"",
            searchlist:{},
        }
    },
    mounted(){
        this.getC()
    },
    methods:{
        getC(){
            let user=this.$store.state.user_id
            if(!user){
                alert('请登录')
                this.$router.push('/login')
                 return
               }
            axios.get('connn/?user_id='+user)
            .then(resp=>{
                console.log(resp);
                this.fabu=resp.data
            })
            .catch(err=>{
                console.log(err);
            })
    },
    searchOne(){
        axios.get('sea/?user_name='+this.name)
        .then(resp=>{
            console.log(resp);
            this.searchlist=resp.data
        })
        .catch(err=>{
            console.log(err);
        })
    },delOne(id){
            axios.delete('connn/?s_id='+id)
            .then(resp=>{
                console.log(resp);
                alert('删除成功')
                his.getC()
            })
            .catch(err=>{
                console.log(err);
            })
    }
    
}
}
</script>

<style>

</style>